package com.ruoyi.web.document;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.document.domain.DocSubjects;
import com.ruoyi.document.service.IDocSubjectsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学科管理Controller
 *
 * @author tom
 * @date 2024-12-04
 */
@RestController
@RequestMapping("/document/subjects")
public class DocSubjectsController extends BaseController
{
    @Autowired
    private IDocSubjectsService docSubjectsService;

    /**
     * 查询学科管理列表
     */
    @PreAuthorize("@ss.hasPermi('document:subjects:list')")
    @GetMapping("/list")
    public TableDataInfo list(DocSubjects docSubjects)
    {
        startPage();
        List<DocSubjects> list = docSubjectsService.selectDocSubjectsList(docSubjects);
        return getDataTable(list);
    }

    /**
     * 导出学科管理列表
     */
    @PreAuthorize("@ss.hasPermi('document:subjects:export')")
    @Log(title = "学科管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DocSubjects docSubjects)
    {
        List<DocSubjects> list = docSubjectsService.selectDocSubjectsList(docSubjects);
        ExcelUtil<DocSubjects> util = new ExcelUtil<DocSubjects>(DocSubjects.class);
        util.exportExcel(response, list, "学科管理数据");
    }

    /**
     * 获取学科管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('document:subjects:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(docSubjectsService.selectDocSubjectsById(id));
    }

    /**
     * 新增学科管理
     */
    @PreAuthorize("@ss.hasPermi('document:subjects:add')")
    @Log(title = "学科管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DocSubjects docSubjects)
    {
        return toAjax(docSubjectsService.insertDocSubjects(docSubjects));
    }

    /**
     * 修改学科管理
     */
    @PreAuthorize("@ss.hasPermi('document:subjects:edit')")
    @Log(title = "学科管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DocSubjects docSubjects)
    {
        return toAjax(docSubjectsService.updateDocSubjects(docSubjects));
    }

    /**
     * 删除学科管理
     */
    @PreAuthorize("@ss.hasPermi('document:subjects:remove')")
    @Log(title = "学科管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(docSubjectsService.deleteDocSubjectsByIds(ids));
    }
}
